<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/3/4-15:33
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->
{extend name='public/base' /}


{block name="content"}

<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-body layui-row ">
            <div class="layui-card-header" style="line-height: 55px;">
                <div class="layui-btn-container do_btn">
                    <!--按钮区-->
                    <button class="layui-btn layui-btn-sm" data-type="add">批量审核<span class="layui-badge">{$num}</span></button>
                    <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="reload"><i class="fa fa-refresh"></i> 刷新</button>
                    <button class="layui-btn layui-btn-sm " id="btn-expand">全部展开</button>
                    <button class="layui-btn layui-btn-sm " id="btn-fold">全部折叠</button>

                </div>
            </div>

        </div>

    </div>

    <div class="layui-card">

        <div class="layui-card-body">

            <!--表格区-->

            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>


{/block}


{block name="js"} <!--js处理区-->


<!--模板-->
<script type="text/html" id="operationTpl">

    {:widget('common/forms/Delbtn',array('删除评论',2))}

</script>



<script type="text/html" id="is_show">
    <input type="checkbox" name="is_show"  lay-data="{{d.is_show}}" value="{{d.id}}"  lay-filter="is_show" lay-skin="switch"  lay-text="是|否"  {{ d.is_show == 1 ? 'checked' : '' }}>
</script>


<script>

    layui.use(['element', 'table', 'form', 'jquery', 'lucky','treetable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var treetable = layui.treetable;

        form.render();

        // layer.load(2);
        treetable.render({
            treeColIndex: 2,
            treeSpid: 0,
            treeIdName: 'id',
            treePidName: 'pid',
            elem: '#tableFilter',
            url:"{:url('comment/index')}",
            page: false,
            cols: [[
                {type: 'checkbox'},
                {field: 'id',  title: 'ID',width:60},
                {field: 'username', width: 180, title: '用户名称'},
                {field: 'content', minWidth: 200, title: '评论内容'},
                {field:'is_show',title:'是否显示',templet: '#is_show',width:110 ,unresize: true},
                {field: 'title',style:'cursor: pointer;',title: '文章标题',width:250},
                {field: 'create_time', title: '评论时间',align: 'center',width:150,sort:true},
                {fixed: 'right',templet: '#operationTpl', width: 80, align: 'center', title: '操作'}
            ]],

            done: function (res) {
                layer.closeAll('loading');
            }
        });

        $('#btn-expand').click(function () {
            treetable.expandAll('#tableFilter');
        });

        $('#btn-fold').click(function () {
            treetable.foldAll('#tableFilter');
        });



        /**
         * 监听是否显示操作
         */
        form.on('switch(is_show)', function(obj){
            var _id=parseInt(obj.value);
            var pan=obj.elem.checked;
            var status;
            if (pan===false){
                status=0;
            }else {
                status=1;
            }
            lucky.Change_status("{:url('common/changeStatus')}","tableFilter","comment",_id,"is_show",status, obj.othis);
        });



        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="del"){
                lucky.Delete_data(_id,"{:url('comment/del')}","tableFilter","确定删除？若有子评论一同删除！");
            }
        });


        var active = {
            add: function(){ //获取选中数据
                var checkStatus = table.checkStatus('tableFilter'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.Delete_data(id,"{:url('comment/checkComment')}","tableFilter","确认审核选中数据？");
            },
            reload: function(){
                lucky.CreateReload("tableFilter");
            }
        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


{/block}
